﻿using MDIDemo.Model;
using MDIDemo.PublicClass;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DevMy.Vou
{
    public partial class Form_Project_TestBase : Form_BaseDialog
    {
        public Form_Project_TestBase()
        {
            InitializeComponent();
        }
        public string mainId;
        public ProjectTestModel projectTestModel;
        public void Ini()
        {
            base.SetComponent();
        }
        /// <summary>
        /// 窗体状态
        /// </summary>
        /// <param name="WinType">-1：查看，0：修改，1：增加</param>
        public void SetWinType(int WinType)
        {
            base.WinType = WinType;
        }

        protected override void DisplayComponent(string id)
        {
            base.class_SetMemoEdit.SetMemoEdit(this.memoEdit1, false);

            if (id != null)
            {

                string Sql = string.Format(@"Select depth,depthMai
                ,sortNo
                ,remark
                From vou_project_test
                Where id = '{0}'
                Order by sortNo", id);
                DataTable dataTable = base.class_MySqlDataBase.GetDataTable(Sql);
                if (dataTable != null && dataTable.Rows.Count == 1)
                {
                    DataRow dataRow = dataTable.Rows[0];
                    if (dataRow != null)
                    {
                        this.spinEdit1.Value = Convert.ToInt32(dataRow["sortNo"].ToString());
                        this.spinEdit2.Value = Convert.ToInt32(dataRow["depth"].ToString());
                        this.spinEdit3.Value = Convert.ToInt32(dataRow["depthMai"].ToString());
                        this.memoEdit1.Text = dataRow["remark"].ToString();
                    }
                }
            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            projectTestModel = new ProjectTestModel();
            if (WinType == 1)
                projectTestModel.id = Class_Tool.GenerateId();
            else
                projectTestModel.id = base.id;
            projectTestModel.mainId = this.mainId;
            projectTestModel.sortNo = Convert.ToInt32(this.spinEdit1.Value);
            projectTestModel.depth = Convert.ToInt32(this.spinEdit2.Value);
            projectTestModel.depthMai = Convert.ToInt32(this.spinEdit3.Value);
            projectTestModel.remark = this.memoEdit1.Text;
            this.DialogResult = DialogResult.OK;
        }
    }
}
